Ext.define("byb.view.system.AdmRole",{
    extend:"Ext.Panel",
    alias:'widget.sysmgr_roleManager',
    border:false,
    layout:"border",
    cls:"BaseManager",
    ui: "byb",
    requires: ['byb.view.system.RoleListView','byb.view.system.MenuTreeView'
               ,"byb.view.baseComponent.button.GridToolbarAllZK"
               ,"byb.view.baseComponent.button.GridToolbarAllSQ"],
    initComponent:function(){
        this.items=[
                     this.buildRoleListView()
                    ,this.buildRoleMgrView()
                    ];
        this.callParent(arguments);
    },
    buildRoleListView:function(){
        return {
            	region:"west",
            	width : 230,
            	xtype: 'panel',
            	autoScroll:true,
            	cls: 'cjb-role-tree',
            	items:[{
            		xtype:'roleListView'
            	}],
    			dockedItems: [{
    				xtype: 'toolbar',
            		dock: 'top',
            		items : [{
	        			xtype : 'button',
	        			action:"addSupporter",
	        			iconCls:"icon-add",
	        			id: "roleMgrAdd",
	        			text : '新增',
	        			disabled: true
	        		},{
	        			xtype : 'button',
	        			action:"removeSupporter",
	                    iconCls:"icon-del",
	        			id: "roleMgrDel",
	        			text : '删除',
	        			disabled: true
	        		}]
            	}],
            	listeners: {
                    afterrender : function(ctx, e, eOpts){
	            		byb.controller.SystemController.reloadAdmRoleStore();
                    }
                }
            };
    },
    buildRoleFormView:function(){
        return {
        	region:"north",
        	layout: 'vbox',
        	border: false,
        	heigth: 130,
        	items: [{
        	        xtype:'form',
        	        border: false,
                    items: [{
		        		xtype:'textfield',
		                fieldLabel: 'ID',
		                name: 'id',
		                style:'display:none'
		            },{
		            	layout:'hbox',
		            	border: false,
		            	items:[{
		            		width:360,
			        		xtype:'textfield',
			                fieldLabel: '角色名称',
			                msgTarget: 'side',
			                emptyText:'请输入角色名称在下面树上选择该角色的权限',
			                name: 'roleName',
			                maxLength: 20,
			                vtype:'normalWithChinese',
			                allowBlank: false,
			                style:'margin-left:30px;margin-top:10px;'
		            	},{
		            		xtype:'button',
			                style:'margin-left:15px;margin-top:10px;',
		            		text:'保存',
		            		id: 'itemSaveRole',
		            		disabled: true
		            	}]
		            },{
		        		xtype:'textfield',
		                fieldLabel: '描&nbsp;&nbsp;&nbsp;&nbsp;述',
		                emptyText:'角色的相关描述信息',
		                width : 600,
		                name: 'discription',
		                maxLength:200,
		                vtype:'normalWithChinese',
		                style:'margin-left:30px;margin-top:10px;'
		            }]
            }]
        };
    },
    buildreloadMenuTreeStore:function(){
    	return {
             region:"center",
    		 border:false,
       	     xtype:"menuTreeView",
             frame:false,
             border:false,
             collapsible:false,
             flex:1,
             dockedItems: [{
                 xtype: 'toolbar',
                 items: [{
                     xtype: 'GridToolbarAllZK',
                     handler: function(){
                    	 Ext.ComponentQuery.query('menuTreeView')[0].expandAll();
                     }
                 }, {
                     xtype: 'GridToolbarAllSQ',
                     handler: function(){
                    	 Ext.ComponentQuery.query('menuTreeView')[0].collapseAll();
                     }
                 }]
           }]
       };
    },
    buildRoleMgrView:function(){
    	return {
    	 layout: 'border',
    	 region:'center',
    	 collapsible:false,
		 border:false,
		 items:[ this.buildRoleFormView(), this.buildreloadMenuTreeStore() ]
    	};
    }
    ,listeners : {
    	afterrender  : function( ctx, eOpts ){
    		if( 'BYB' === byb.controller.SystemController.loginUserOrgCode){
	    		Ext.getCmp('roleMgrAdd').enable();
	    		Ext.getCmp('roleMgrDel').enable();
	    		Ext.getCmp('itemSaveRole').enable();
    		}
        }
    }
});